﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

using agvcontroller.Common.DataBase;
using agvcontroller.Log;

namespace agvcontroller.Common
{
    public class CCommType
    {
        List<string> _CommTypeList = new List<string>();
        public List<string> CommTypeList
        {
            get { return _CommTypeList; }
        }

        CAGVCDB AGVCDB;

        Logger Log;

        public CCommType()
        {
            Log = new Logger("CommType");

            AGVCDB = CAGVCDB.getInstance();

            GetDataFromDB();
        }

        int GetDataFromDB()
        {
            DataTable table = AGVCDB.AGVCDataSet.Tables["CommType"];

            try
            {
                _CommTypeList.Clear();

                foreach (DataRow row in table.Rows)
                {
                    _CommTypeList.Add(Convert.ToString(row["Type"]));
                }

                if (_CommTypeList.Count == 0)
                {
                    Log.Info(string.Format("Communication Type List item is empty"));
                }
            }
            catch (Exception ex)
            {
                Log.Exception(string.Format("{0},{1}", ex.Message, ex.StackTrace));
                return CReturnCode.ERR_DATA_ACQUIRING_FAIL;
            }

            return CReturnCode.SUCCESS;
        }
    }
}
